package com.umpay.controller.payment;

import com.umpay.annotation.ReceiveEntity;
import com.umpay.business.payment.PaymentBusinessService;
import com.umpay.controller.base.AbstractController;
import com.umpay.dto.UMFRequest;
import com.umpay.dto.UMFResponse.Message;
import com.umpay.dto.merAccess.req.payment.WechatPlatformPayReq;
import com.umpay.dto.merAccess.res.payment.WechatPlatformPayRes;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName: WechatPlatformPayController
 * @Description: 公众号支付
 * @author chenxinyu
 * @date July 2, 2018
 */
@RestController
@SuppressWarnings("unchecked")
public class WechatPlatformPayController extends AbstractController {

    private static final Logger log = LogManager.getLogger(WechatPlatformPayController.class);

    @Autowired
    private PaymentBusinessService paymentBusiness;

    @PostMapping("/payment/wechatPlatformPay")
    @ReceiveEntity(type = WechatPlatformPayReq.class)
    public Message<WechatPlatformPayRes> wechatPlatformPayReq(HttpServletRequest request, HttpServletResponse response) {
        
    	UMFRequest<WechatPlatformPayReq> umfRequest = (UMFRequest<WechatPlatformPayReq>) request.getAttribute(UMFRequest.REQUEST);
        log.info(String.format("公众号支付接受请求参数[%s]", umfRequest));
        WechatPlatformPayReq wechatPlatformPayReq = umfRequest.getMessage();
        Message<WechatPlatformPayRes> wechatPlatformPayRes = this.paymentBusiness.wechatPlatformPay(wechatPlatformPayReq);
        log.info(String.format("公众号支付相应数据[%s]", wechatPlatformPayRes));
        return responseMsg(wechatPlatformPayRes, response);
    }

}
